;;; buffer.cfg.el --- Summary
;;; Commentary:
;;; configuration for buffer-related stuff.
;;; Code:

(require 'package.cfg)

(defun my-shell-turn-echo-off ()
  (setq comint-process-echoes t))
(add-hook 'shell-mode-hook 'my-shell-turn-echo-off)

(global-set-key (kbd "RET") 'newline-and-indent)

(setq require-final-newline t)

;; Start from the top when usint C-l
(setq recenter-positions '(top middle bottom))

;; use shift to move around windows
(windmove-default-keybindings 'shift)
;; Window splitting and navigation.
(winner-mode 1)
(package-install-if-absent 'windresize)
(use-package windresize)

;; Make unique buffer names better.
;; That's the default in emacs 24.4.
(cond ((string< emacs-version "24.4")
       (require 'uniquify)
       (setq uniquify-buffer-name-style 'post-forward-angle-brackets)))

;; http://www.masteringemacs.org/articles/2014/02/28/my-emacs-keybindings/
(defun kill-this-buffer ()
  "Kill the current buffer."
  (interactive)
  (kill-buffer (current-buffer)))
(global-set-key "\C-x\C-k" 'kill-this-buffer)

(defun revert-this-buffer ()
  "Revert the current buffer."
  (interactive)
  (revert-buffer nil t t)
  (message (concat "Reverted buffer " (buffer-name))))
(global-set-key [f6] 'revert-this-buffer)


(global-set-key [remap goto-line] 'goto-line-with-feedback)

;; http://whattheemacsd.com/key-bindings.el-01.html
(defun goto-line-with-feedback ()
  "Show line numbers temporarily, while prompting for the line number input."
  (interactive)
  (unwind-protect
      (progn
        (linum-mode 1)
        (goto-line (read-number "Goto line: ")))
    (linum-mode -1)))

;; http://www.emacswiki.org/emacs/FlySpell
;; Printing messages for every word (when checking the entire buffer) causes an enormous slowdown.
(setq flyspell-issue-message-flag nil)

(when
    (executable-find "aspell")
  (setq ispell-program-name "aspell"
        ;; http://www.emacswiki.org/emacs/FlySpell
        ;; Use --list instead of -l because the -l option means --lang in aspell
        ispell-list-command "--list"
        ;; http://blog.binchen.org/posts/effective-spell-check-in-emacs.html
        ;; force the English dictionary, support Camel Case spelling check (--run-together)
        ispell-extra-args '("--sug-mode=ultra" "--lang=en_US" "--run-together" "--run-together-limit=5" "--run-together-min=2")))

(package-install-if-absent 'drag-stuff)
(use-package drag-stuff
  :init
  (drag-stuff-global-mode t)
  :diminish drag-stuff-mode)

(package-install-if-absent 'clean-aindent-mode)
(use-package clean-aindent-mode
  :init
  (add-hook 'prog-mode-hook 'clean-aindent-mode))

;; unobtrusively trim white spaces from end of line
(package-install-if-absent 'ws-butler)
(use-package ws-butler
  :init
  (add-hook 'prog-mode-hook 'ws-butler-mode)
  :diminish ws-butler-mode)

(provide 'buffer.cfg)
;;; buffer.cfg.el ends here
